package com.smmisia.article.controller;

import com.smmisia.article.request.AttractionCreateRequest;
import com.smmisia.article.request.AttractionUpdateRequest;
import com.smmisia.article.response.AttractionResponse;
import com.smmisia.article.service.AttractionService;
import com.smmisia.common.Result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/attraction")
@Tag(name = "景点管理")
public class AttractionController {

    @Autowired
    private AttractionService attractionService;

    /**
     * 创建景点
     * @param attractionCreateRequest
     * @return
     */
    @PostMapping("/create")
    @Operation(summary = "创建景点")
    public Result<Boolean> create(@Valid @RequestBody AttractionCreateRequest attractionCreateRequest){
        return attractionService.create(attractionCreateRequest);
    }

    /**
     * 更新景点
     * @param attractionUpdateRequest
     * @return
     */
    @PostMapping("/update")
    @Operation(summary = "创建景点")
    public Result<Boolean> update(@Valid @RequestBody AttractionUpdateRequest attractionUpdateRequest){
        return attractionService.updateInfo(attractionUpdateRequest);
    }

    /**
     * 删除景点
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @Operation(summary = "删除景点")
    public Result<Boolean> delete(@RequestParam(value = "id") @NotNull(message = "不能为空") Integer id){
        return attractionService.delete(id);
    }

    /**
     * 查询景点
     * @param id
     * @return
     */
    @GetMapping("/info")
    @Operation(summary = "根据id查询景点")
    public Result<AttractionResponse> info(@RequestParam(value = "id") @NotNull(message = "不能为空") Integer id){
        return attractionService.info(id);
    }

    /**
     * 查询景点列表
     * @param id
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "根据景区id查询景点")
    public Result<List<AttractionResponse>> list(@RequestParam(value = "id") @NotNull(message = "不能为空") Integer id){
        return attractionService.getList(id);
    }

}
